import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/req/other/req_other.dart';
import 'package:flutter_changdian_football/config/enum/load_state.dart';
import 'package:flutter_changdian_football/model/other/news_detail_model.dart';
import 'package:flutter_changdian_football/widget/toast/custom_toast.dart';
import 'package:get/get.dart';

class NewsDetailController extends GetxController {

  NewsDetailController({
    required this.newsId
  });

  final String newsId;

  @override
  void onInit() {
    super.onInit();
    initData();
  }

  LoadState state = LoadState.loading;
  NewsDetailModel? newsDetailModel;

  initData() async {
    var resp = await ReqOther.newsContent(newsId: newsId);
    if (resp.status == Status.completed) {
      if (resp.data['code'] == '200') {
        newsDetailModel = NewsDetailModel.fromJson(resp.data['data']);

        if (newsDetailModel != null) {
          state = LoadState.success;
        } else {
          state = LoadState.empty;
        }

        update();
      } else {
        CustomToast.showTextToast('${resp.data['msg']}');
        state = LoadState.error;
        update();
      }
    } else {
      state = LoadState.network;
      update();
    }
  }

}